from base import By, webdriver, sleep
# 导入键盘类
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome()
driver.get('https://www.baidu.com')

# 定位输入框,输入搜索内容
sleep(2)
kw = driver.find_element(By.ID, 'kw')
kw.send_keys('武汉天气')

# Ctrl a 全选
sleep(2)
kw.send_keys(Keys.CONTROL, 'a')

# Ctrl c 复制
kw.send_keys(Keys.CONTROL, 'c')

# 请求so
sleep(2)
driver.get('https://www.so.com')

# 定位搜索框,粘贴内容  Ctrl v
ipt = driver.find_element(By.ID, 'input')
sleep(2)
ipt.send_keys(Keys.CONTROL, 'v')

"""
# 定位搜素按钮,点击搜索
driver.find_element(By.ID, 'search-button').click()
"""
# 回车键操作
ipt.send_keys(Keys.ENTER)

# 退出浏览器
sleep(3)
driver.quit()
